package com.onlinemarket.thrid.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.onlinemarket.thrid.daoimpl.StroageDaoImpl;
import com.onlinemarket.thrid.domain.Goods;
import com.onlinemarket.thrid.domain.Stroage;

@Controller
@RequestMapping(value = "/stroage")
public class StroageControl {
	@Autowired
	private StroageDaoImpl stroagedaoimpl;
	private ModelAndView modelAndView = new ModelAndView();

	/**
	 * 跳转至商品入库界面
	 * 
	 * @return
	 */
	@RequestMapping(value = "/toStroagePage")
	public ModelAndView toStroagePage() {
		List<Goods> allgoods = stroagedaoimpl.getallGoods();
		modelAndView.addObject("allgoods", allgoods);
		modelAndView.setViewName("stroage/add");
		return modelAndView;
	}

	/**
	 * 添加库存
	 * 
	 * @return
	 */
	@RequestMapping(value = "/addstroage")
	public ModelAndView addstroage(int goods,int number,String localdate) {
		Stroage s = new Stroage();
		s.setStroage_number(number);
		s.setStroage_date(localdate);
		s.setGoods_id(goods);
		boolean isadd = stroagedaoimpl.addstorage(s);
		if (isadd) {
			modelAndView.setViewName("success");
		} else {
			modelAndView.setViewName("fail");
		}
		return modelAndView;
	}
}
